<?php

/**
 * Invoice form base class.
 *
 * @method Invoice getObject() Returns the current form's model object
 *
 * @package    Serag
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseInvoiceForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'            => new sfWidgetFormInputHidden(),
      'invoice_code'  => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('InvoiceProduct'), 'add_empty' => false)),
      'customer_id'   => new sfWidgetFormInputText(),
      'user_id'       => new sfWidgetFormInputText(),
      'amount'        => new sfWidgetFormInputText(),
      'created_at'    => new sfWidgetFormDateTime(),
      'discount'      => new sfWidgetFormInputText(),
      'discount_type' => new sfWidgetFormChoice(array('choices' => array('percentage' => 'percentage', 'cash' => 'cash'))),
      'line_id'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Line'), 'add_empty' => true)),
      'date'          => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'            => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'invoice_code'  => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('InvoiceProduct'), 'required' => false)),
      'customer_id'   => new sfValidatorInteger(array('required' => false)),
      'user_id'       => new sfValidatorInteger(array('required' => false)),
      'amount'        => new sfValidatorNumber(),
      'created_at'    => new sfValidatorDateTime(array('required' => false)),
      'discount'      => new sfValidatorInteger(array('required' => false)),
      'discount_type' => new sfValidatorChoice(array('choices' => array(0 => 'percentage', 1 => 'cash'), 'required' => false)),
      'line_id'       => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Line'), 'required' => false)),
      'date'          => new sfValidatorDateTime(array('required' => false)),
    ));

    $this->widgetSchema->setNameFormat('invoice[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Invoice';
  }

}
